/*
* @Author: Rosen
* @Date:   2018-02-02 12:24:13
* @Last Modified by:   Rosen
* @Last Modified time: 2018-02-02 16:29:06
*/
import React        from 'react';
import FileUpload   from './react-fileupload.jsx';
//文件上传
class FileUploader extends React.Component{
    render(){
        const options={
            baseUrl         :'/manage/product/upload.do',
            fileFieldName   : 'upload_file',//传给后端的文件名
            dataType        : 'json',
            chooseAndUpload : true, //表示自动上传
              withCredentials: true, // 设置为true 表示跨域上传哦，，一定要设置，坑了1天的时间

        
            uploadSuccess   : (res) => {
                this.props.onSuccess(res.data); //上传成功调用父级的onsuccess方法，。product/save.jsx/onsucdess
            },
            uploadError     : (err) => {
                this.props.onError('上传图片失败' || '上传图片出错啦');
            }
        }
        return (
            <FileUpload options={options}>
                <button className="btn btn-xs btn-default" ref="chooseAndUpload">选择图片</button>
            </FileUpload>
        )           
    }
}
export default FileUploader;